<template>
  <div class="mod-menu">
    <el-form :inline="true" :model="dataForm">
      <el-form-item>
        <el-button v-if="isAuth('sys:menu:save')"  :type="button01"  @click="getDataList('0')">数据中心</el-button>
        <el-button v-if="isAuth('sys:menu:save')"  :type="button02"  @click="getDataList('1')">安全域</el-button>
        <el-button v-if="isAuth('sys:menu:save')"  :type="button03"  @click="getDataList('2')">租户</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      style="width: 100%;">
      <el-table-column
        prop="id"
        header-align="center"
        align="center"
        width="80"
        label="ID">
      </el-table-column>
      <table-tree-column
        prop="resourceName"
        header-align="center"
        treeKey="id"
        width="150"
        label="资源名称">
      </table-tree-column>
      <el-table-column
        prop="belongRegion"
        header-align="center"
        align="center"
        label="所属域">
      </el-table-column>
      <el-table-column
        prop="belongTenant"
        header-align="center"
        align="center"
        width="150"
        :show-overflow-tooltip="true"
        label="所属租户">
      </el-table-column>
      <el-table-column
        prop="belongServer"
        header-align="center"
        align="center"
        width="150"
        :show-overflow-tooltip="true"
        label="所属服务器">
      </el-table-column>
      <el-table-column
        prop="ifOnline"
        header-align="center"
        align="center"
        width="150"
        :show-overflow-tooltip="true"
        label="在线状态">
      </el-table-column>
      <el-table-column
        prop="onlineTime"
        header-align="center"
        align="center"
        width="150"
        :show-overflow-tooltip="true"
        label="加入系统时间">
      </el-table-column>
      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="150"
        label="操作">
        <template slot-scope="scope">
          <el-button v-if="scope.row.ifOnline !== '-'" type="text" size="small" @click="performance(scope.row.uuid)">性能数据</el-button>
          <span v-if="scope.row.ifOnline === '-'"> - </span>
          <!-- <el-button v-if="scope.row.ifOnline !== '-'" type="text" size="small" @click="deleteHandle(scope.row.menuId)">历史信息</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <!-- 弹窗, 新增 / 修改 -->
    <performance-data v-if="addOrUpdateVisible" ref="addOrUpdate" @addOrUpdateHide="addOrUpdateHide" @refreshDataList="getDataList"></performance-data>
  </div>
</template>

<script>
  import TableTreeColumn from '@/components/table-tree-column'
  import performanceData from './performanceData'
  import { treeDataTranslate } from '@/utils'
  export default {
    data () {
      return {
        dataForm: {},
        dataList: [],
        dataListLoading: false,
        addOrUpdateVisible: false,
        button01: '',
        button02: '',
        button03: ''
      }
    },
    components: {
      TableTreeColumn,
      performanceData
    },
    activated () {
      this.getDataList('0')
    },
    methods: {
      // 获取数据列表
      getDataList (val) {
        this.button01 = val === '0' ? 'primary' : ''
        this.button02 = val === '1' ? 'primary' : ''
        this.button03 = val === '2' ? 'primary' : ''
        this.dataListLoading = true
        let params = {
          type: val
        }
        this.$http({
          url: this.$http.preBaseUrl('/cs/baseinfo/list'),
          method: 'get',
          params:params
        }).then(({data}) => {
          this.dataList = treeDataTranslate(data.list, 'id', 'parentId')
          this.dataListLoading = false
        })
      },
      addOrUpdateHide () {
        this.addOrUpdateVisible = false
      },
      performance (ud) {
        if (ud) {
          this.addOrUpdateVisible = true
          this.$nextTick(() => {
            this.$refs.addOrUpdate.init(ud)
          })
        }
      },
      // 删除
      // deleteHandle (id) {
      //   this.$confirm(`确定对[id=${id}]进行[删除]操作?`, '提示', {
      //     confirmButtonText: '确定',
      //     cancelButtonText: '取消',
      //     type: 'warning'
      //   }).then(() => {
      //     this.$http({
      //       url: this.$http.adornUrl(`/sys/menu/delete/${id}`),
      //       method: 'post',
      //       data: this.$http.adornData()
      //     }).then(({data}) => {
      //       if (data && data.code === 0) {
      //         this.$message({
      //           message: '操作成功',
      //           type: 'success',
      //           duration: 1500,
      //           onClose: () => {
      //             this.getDataList()
      //           }
      //         })
      //       } else {
      //         this.$message.error(data.msg)
      //       }
      //     })
      //   }).catch(() => {})
      // }
    }
  }
</script>
